package com.core;

import java.text.ParseException;

import com.core.SeatManager.SeatCode;

public class Helper {

	public static String parseSeatCode(String seatCode, SeatCode part){
		String value = "";
		switch (part) {
		case LOCATIONCODE :
			value = seatCode.substring(0, 3);
			break;
		case FLOOR :
			seatCode = seatCode.substring(3, seatCode.lastIndexOf("F") );
			if(seatCode.equalsIgnoreCase("3")) {value = "1";}
			if(seatCode.equalsIgnoreCase("4")) {value = "2";}
			if(seatCode.equalsIgnoreCase("12")) {value = "3";}	
			break;
		case QUADRANT :
			value = seatCode.substring(seatCode.lastIndexOf("F")+1, seatCode.lastIndexOf("F")+2);
			break;
		case COLUMN :
			value = seatCode.substring(seatCode.lastIndexOf("F")+2, seatCode.length() -(seatCode.length() -seatCode.lastIndexOf("-")));
			break;
		case ROW :
			value = seatCode.substring(seatCode.lastIndexOf("-")+1, seatCode.length());
			break;
		}
		
		return value;
	}
	
	public static boolean isInteger(String str){
		try {
			Integer.parseInt(str);
		} catch (Exception e) {
			return false;
		}
		return true;
	}
}
